package com.testplatfrom.project.controller;


import com.testplatfrom.common.core.domain.R;
import com.testplatfrom.common.log.annotation.Log;
import com.testplatfrom.common.log.enums.BusinessType;
import com.testplatfrom.common.security.annotation.RequiresPermissions;
import com.testplatfrom.project.domain.dto.member.TestplatfromProjectmemDeleteUser;
import com.testplatfrom.project.domain.dto.member.TestplatfromProjectmemberAdd;
import com.testplatfrom.project.domain.dto.member.TestplatfromProjectmemberPage;
import com.testplatfrom.project.service.TestplatfromProjectmemberService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 杨森
 * @since 2023-07-13
 */
@RestController
@RequestMapping("/testplatfromProjectmember")
public class TestplatfromProjectmemberController {


    @Autowired
    private TestplatfromProjectmemberService testplatfromProjectmemberService;


    /**
     * 新增项目管理人员
     */
    @ApiOperation(value = "新增项目管理人员接口", notes = "新增项目管理人员接口")
    @RequiresPermissions("project:member:add")
    @Log(title = "项目新增人员", businessType = BusinessType.INSERT)
    @PostMapping
    public R<Boolean> add(@Valid @RequestBody TestplatfromProjectmemberAdd testplatfromProjectmemberAdd) {
        return R.ok(testplatfromProjectmemberService.addTestplatfromProjectMember(testplatfromProjectmemberAdd));
    }


    /**
     * 项目管理人员列表
     */
    @ApiOperation(value = "项目管理人员列表", notes = "项目管理人员列表")
    @RequiresPermissions("project:member:list")
    @Log(title = "获取项目人员详情", businessType = BusinessType.OTHER)
    @PostMapping("/list")
    public R projectMemberPage(@RequestBody TestplatfromProjectmemberPage testplatfromProjectmemberPage) {
        return R.ok(testplatfromProjectmemberService.listTestplatfromProjectMember(testplatfromProjectmemberPage));
    }

    /**
     * 移除项目管理人员
     */
    @ApiOperation(value = "移除项目管理人员", notes = "移除项目管理人员")
    @RequiresPermissions("project:member:delete")
    @Log(title = "移除项目管理人员", businessType = BusinessType.DELETE)
    @DeleteMapping("/delete/{id}")
    public R detailPage(@PathVariable("id") String id) {
        return R.ok(testplatfromProjectmemberService.deleteTestplatfromProjectMember(id));
    }

    /**
     * 移除项目管理人员
     */
    @ApiOperation(value = "移除项目管理人员", notes = "移除项目管理人员")
    @RequiresPermissions("project:member:delete")
    @Log(title = "移除项目管理人员", businessType = BusinessType.DELETE)
    @PostMapping("/deleteUsers")
    public R deleteUsers(@Valid @RequestBody TestplatfromProjectmemDeleteUser testplatfromProjectmemDeleteUser) {
        return R.ok(testplatfromProjectmemberService.deleteTestplatfromProjectMemberUsers(testplatfromProjectmemDeleteUser));
    }


    /**
     * 返回所有人员
     */
    @ApiOperation(value = "返回所有人员", notes = "返回所有人员")
    @GetMapping("/userlist")
    public R getAllUserlist() {
        return testplatfromProjectmemberService.getAllUser();
    }

}

